/******************************init****************************/
function queryRecruitInfo(page) {
	var parm = $('#queryRecruitInfoForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('recruitinfo-query');
	sys_record_parm('recruitinfo',parm);
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultList').html(result);
		}
	});
}
function querySupplyInfo(page) {
	var parm = $('#querySupplyInfoForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('supplyinfo-query');
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultList').html(result);
		}
	});
}
function deleteSupplyInfo(code) {
	$.Zebra_Dialog('是否删除',{
				'type': 'question',
				'title': '警告' ,
				'buttons':[
				           {caption:'删除',callback:function() {
				        	    var url = create_url('supplyinfo-delete');
						    	supplyInfo_aidExecute(code, url);
				    		}},
				           {caption:'取消',callback:function(){}
				    	}]
				});
}
function supplyInfo_aidExecute(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功');
				querySupplyInfo();
			} else {
				sys_msg('操作失败');
				querySupplyInfo();
			}
		}
	});
}

function editSupplyJoinInfo(code){
	var url = create_url('supplyinfo-querySupplyJoinInit');
	var parm = {"code": code};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'750px',height:'500px', open:true});
}

/******************************edit****************************/
function saveSupplyInfo() {
	setCover();
	var parm = $('#editSupplyInfoForm').serialize() + '&content=' + fixJqText(Url.encode(content.getData()));
	var url = create_url('supplyinfo-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
		sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功!');
				sys_load_handle('supplyinfo');
			}
		}
	});
}

function addFilesUploadEvent_SupplyInfo() {
	var url = create_url('supplyinfo-uploads');
	var btn = $('#uploadFilesBtn');
	new AjaxUpload(btn, {
		action:url,
		name:'files',
		multiple: true,
		responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(jpg|png|jpeg|gif|bmp|JPG|PNG|JPEG|GIF|BMP)$/.test(ext)){
				this.setData({'info':'文件类型正确'});
			} else {
				sys_msg('文件类型错误', '只能上传类型为：jpg、png、jpeg、gif、bmp、图片文件!尺寸小于300*300最佳');
				return false;               
			}
			$('#upload_span').html(sys_loading_img);
			this.disable();
		},
		onComplete: function(files, response){
			if ('error' == response.result)
				sys_msg('失败', '上传文件失败，请检查文件名是否正确!');
			else if ('file_type_error' == response.result)
				sys_msg('文件类型错误', '只能上传类型为：jpg、png、jpeg、gif、bmp、图片文件!');
			else {
				var template = $('#tempAnnexListDiv').find('.rep');
				var annexList = $('#annexListTable');
				var index = parseInt($('#supplyinfo_an_index').val());
				$.each(response.list, function(i) {
					var pii = template.clone(true);
					pii.find('.title').html(response.list[i].name).end()
						.find('.name').attr('name', 'List[' + (index) + '].name').val(response.list[i].name).end()
						.find('.size').attr('name', 'List[' + (index) + '].size').val(response.list[i].size).end()
						.find('.sn').attr('name', 'List[' + (index) + '].sn').val(response.list[i].path).end()
						.find('.ext').attr('name', 'List[' + (index) + '].ext').val(response.list[i].ext).end()
						.find('.afcs').val(response.list[i].code).end()
						.find('.font-cover').val(response.list[i].code).end();
					annexList.append(pii);
					index ++;
					$('#supplyinfo_an_index').val(index);
				});
				this.enable();
				
			}
		}
	});
}
function deleteSelectedItem(btn) {
	btn.parents('.rep').remove();
}

function setCover(){
	var cover = $("input[name=choose]:checked").val();
	$("#fileCode").val(cover);
}

function checkedSupplyInfo(){
	var tile = $("#title").val();
	var address = $("#address").val();
	var num = $("#num").val();
	if(title.length==0){
		sys_msg('必须填写标题');
		return
	}
	if(address.length==0){
		sys_msg('必须填写地址');
		return
	}
    if(!$.isNumeric(num)){
    	sys_msg('数量必须是数字');
		return
	}
	saveSupplyInfo();
}
/******************************aidinit****************************/
function querySupplyJoin(page) {
	var parm = $('#querySupplyJoinForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('supplyinfo-querySupplyJoinList');
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultList1').html(result);
		}
	});
}

function chooseDetail(code) {
	var url = create_url('supplyinfo-querySupplyJoinInfoDetail');
	var parm = {'code': code};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px',height:'600px', open:true});
}

function bidOrganSave(name,sic){
	if(confirm("确认这家公司中标?")){
  		var parm = {'name': name, 'sic':sic};
		var url = create_url('supplyinfo-saveBidOrgan');
		sys_submiting();
		$.ajax({type:'POST', url:url, data:parm,
			success: function(result) {
			sys_submiting_close();
				if ('success' == result) {
					$.fn.colorbox.close();
					sys_msg('操作成功');
					sys_load_handle('supplyinfo');
				}
			}
		});
  	 }
}
/************aidinit******************/

